﻿Imports System.Data
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types

Public Class Adddata

    Dim objConn As OracleConnection
    Dim cmd As OracleCommand
    Dim dtadapter As OracleDataAdapter
    Dim da As OracleDataAdapter
    Dim cb As OracleCommandBuilder
    Dim ds As DataSet
    Dim Udone As New Err
    Dim Done As New Done
    Dim infor As New infor


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub

    Private Sub Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add.Click
        If ID.Text = "" Or M_ID.Text = "" Or C_ID.Text = "" Or Si.Text = "" Or Med_N.Text = "" _
            Or TextBox2.Text = "" Or TextBox3.Text = "" Or How.Text = "" Or Prop.Text = "" Or _
            Cu.Text = "" Then
            infor.ShowDialog()
        Else
            Dim strConnString As String = Login.strConn
            objConn = New OracleConnection(strConnString)
            Dim cmd As New OracleCommand
            Dim cmd2 As New OracleCommand
            Dim str1 As String = ""
            Dim str2 As String = ""
            Dim str4 As String = ""
            Dim str5 As String = ""
            Dim str6 As String = ""
            Dim str7 As String = ""
            Dim str8 As String = ""
            Dim str9 As String = ""
            Dim str10 As String = ""
            Dim str11 As String = ""
            Dim str12 As String = ""
            Dim str13 As String = ""

            str1 = ID.Text
            str2 = Med_N.Text
            str4 = C_ID.Text
            str5 = Si.Text
            str6 = Prop.Text
            str7 = How.Text
            str8 = Cu.Text
            str9 = M_ID.Text
            str10 = TextBox2.Text
            str11 = DT1.Value
            str12 = DT2.Value
            str13 = TextBox3.Text

            Try
                Dim sql As String = "Insert into MEDICINES VALUES('" + str1 + "','" + str2 + "','" + str4 + "','" + str5 + CB3.Text + "', '" _
                                    + str6 + "','" + str7 + "','" + str8 + "','" + str9 + "')"
                objConn.Open()
                With cmd
                    .Connection = objConn
                    .CommandText = sql
                    .CommandType = CommandType.Text
                End With
                Try
                    cmd.ExecuteNonQuery()
                Catch ex As Exception
                    Udone.ShowDialog()
                End Try

                Dim sql2 As String = "Insert into LOTS VALUES('" + str1 + "','" + ComboBox1.Text + str10 + "','" + str11 + "','" + str12 + "', '" _
                                    + str13 + "')"
                With cmd2
                    .Connection = objConn
                    .CommandText = sql2
                    .CommandType = CommandType.Text
                End With
                Try
                    cmd2.ExecuteNonQuery()
                    Done.ShowDialog()
                Catch ex As Exception
                    Udone.ShowDialog()
                End Try
            Catch ex As Exception
                Udone.ShowDialog()
            Finally
                objConn.Dispose()
                DATASC()
                ID.Text = ""
                Med_N.Text = ""
                C_ID.Text = ""
                Si.Text = ""
                Prop.Text = ""
                How.Text = ""
                Cu.Text = ""
                M_ID.Text = ""
                TextBox2.Text = ""
                TextBox3.Text = ""
                DT1.Value = Today
                DT2.Value = Today
            End Try            
        End If
    End Sub

    Private Sub Adddata_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DATASC()
        C_ID.Text = ""
        M_ID.Text = ""
    End Sub

    Private Sub DATASC()
        Dim strConnString As String
        strConnString = Login.strConn
        objConn = New OracleConnection(strConnString)
        objConn.Open()
        Dim cmd3 As New OracleCommand
        Dim sql1 As String = "select * from TYPE"
        cmd3 = New OracleCommand(sql1, objConn)
        da = New OracleDataAdapter(cmd3)
        cb = New OracleCommandBuilder(da)
        ds = New DataSet()
        da.Fill(ds, "TYPE")

        With Me.C_ID
            .DataSource = ds.Tables("TYPE")
            .DisplayMember = "TYPE_MED"
            .ValueMember = "TYPE_ID"
        End With

        Dim sql2 As String = "select * from MANUFACTUR"
        cmd3 = New OracleCommand(sql2, objConn)
        da = New OracleDataAdapter(cmd3)
        cb = New OracleCommandBuilder(da)
        ds = New DataSet()
        da.Fill(ds, "MANUFACTUR")

        With Me.M_ID
            .DataSource = ds.Tables("MANUFACTUR")
            .DisplayMember = "MANUFAC_NAME"
            .ValueMember = "MANUFAC_ID"
        End With
    End Sub

End Class